package com.example.weight.wormHandle;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.weight.R;
import com.example.weight.wormHandle.cultivate.cultivateNav;
import com.example.weight.wormHandle.garbageDisposal.garbageDisposalNav;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

public class wormHandleNav extends AppCompatActivity {

    private Button cultivateNav, wormKingNav, garbageDisposalNav;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_worm_handle_nav);

        Intent previousIntent = getIntent();
        final String name = previousIntent.getStringExtra("name");
        final String factory = previousIntent.getStringExtra("factory");
        String permissionLevel = previousIntent.getStringExtra("permissionLevel");

        TitleBar titleBar = findViewById(R.id.titleBar);
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {}

            @Override
            public void onRightClick(View v) {}
        });

        cultivateNav = findViewById(R.id.cultivate_nav);
        wormKingNav = findViewById(R.id.worm_king_nav);
        garbageDisposalNav = findViewById(R.id.garbage_disposal_nav);

        cultivateNav.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(wormHandleNav.this, cultivateNav.class);
                intent.putExtra("name", name);
                intent.putExtra("factory", factory);
                startActivity(intent);
            }
        });

        wormKingNav.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(wormHandleNav.this, wormHandleNav.class);
                intent.putExtra("name", name);
                intent.putExtra("factory", factory);
                startActivity(intent);
            }
        });

        garbageDisposalNav.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(wormHandleNav.this, garbageDisposalNav.class);
                intent.putExtra("name", name);
                Log.d("wormhandle",factory);
                intent.putExtra("factory", factory);
                startActivity(intent);
            }
        });

        initNavEnable(permissionLevel);
    }

    private void initNavEnable(String permissionLevel) {
        if (permissionLevel.equals("0"))
            return;
        cultivateNav.setEnabled(false);
        wormKingNav.setEnabled(false);
        garbageDisposalNav.setEnabled(false);
        if (permissionLevel.contains("培育"))
            cultivateNav.setEnabled(true);
        if (permissionLevel.contains("种虫养殖"))
            wormKingNav.setEnabled(true);
        if (permissionLevel.contains("垃圾处理"))
            garbageDisposalNav.setEnabled(true);
    }
}